﻿using NETworkManager.Utilities;
using System;
using System.Security;

namespace NETworkManager.Profiles
{
    public class ProfileFileInfo
    {
        /// <summary>
        /// Make object unique.
        /// </summary>
        private Guid ID { get; }

        /// <summary>
        /// Name of the profile. This is the filename without extension.
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// Full path of the profile file.
        /// </summary>
        public string Path { get; set; }

        /// <summary>
        /// Indicates if the profile file is encrypted.
        /// </summary>        
        public bool IsEncrypted { get; set; }

        /// <summary>
        /// Password to encrypt and decrypt the profile file.
        /// </summary>
        public SecureString Password { get; set; }

        /// <summary>
        /// Indicates if the password is valid and can be used for encryption or decryption.
        /// </summary>
        public bool IsPasswordValid { get; set; }

        /// <summary>
        /// Profile file info contains all necessary informations about the profile file and location.
        /// </summary>
        /// <param name="name"><see cref="Name"/> of the profile file.</param>
        /// <param name="path"><see cref="Path"/> of the profile file.</param>
        /// <param name="isEncrypted"><see cref="IsEncrypted"/> indicates if the file is encrypted.</param>
        public ProfileFileInfo(string name, string path, bool isEncrypted = false)
        {
            ID = Guid.NewGuid();
            Name = name;
            Path = path;
            IsEncrypted = isEncrypted;
        }

        /// <summary>
        /// Overrides the default <see cref="Equals(object)"/> method.
        /// </summary>
        /// <param name="obj">Object from type <see cref="ProfileFileInfo"/>.</param>
        /// <returns>Returns true if the <see cref="ProfileFileInfo"/> is equal to another <see cref="ProfileFileInfo"/>.</returns>
        public override bool Equals(object obj)
        {
            if (!(obj is ProfileFileInfo info))
                return false;

            return info.ID == ID;
        }

        /// <summary>
        /// Overrides the default GetHashCode() method.
        /// </summary>
        /// <returns>Return the hashcodes generated by the path of the <see cref="ProfileFileInfo"/>.</returns>
        public override int GetHashCode()
        {
            return ID.GetHashCode();            
        }
    }
}
